﻿@model IEnumerable<WarOfDev.Web.Models.MessageModel>
@{
    ViewBag.Title = "Home Page";
}
<div class="container_12 grid_6">
    <div class="message-buttons">
        <ul>
            <li class="share">Share an Update &nbsp;&nbsp;&nbsp;</li>
            <li class="attachs">
            <input type='hidden' id= "FileGuidList" />
            <input type='hidden' id= "FileNameList" />
            <input type="file" id="photo" name="photo"/></li>
        </ul>
    </div>
    <div class="">
        @Html.TextArea("message", new { rows = 5, cols = 50 })
        <input id="btnEnterMessage" value="Post" type="button" />
    </div>
</div>
@Html.Action("List", "Message")
<script type="text/javascript" src="/Scripts/swfupload.js"></script>
<script type="text/javascript" src="/Scripts/jquery-asyncUpload-0.1.js"></script>

<script type="text/javascript">
    $(function () {
        $("#photo").makeAsyncUploader({
            upload_url: "/Message/GetAttachFileGuid",
            flash_url: '/Scripts/swfupload.swf',
            button_image_url: '/Images/blankButton.png',
            disableDuringUpload: 'INPUT[type="submit"]'
        });
    });
</script>  
<script type="text/javascript">


    $("#btnEnterMessage").bind("click", function () {
        $.ajax({
            url: "@(Url.Action("Post", "Message"))",
            data: { message: $("#message").val() , FileNameList: $("#FileNameList").val(), FileGuidList: $("#FileGuidList").val() },
            type: "post",
            success: function (e) {
                if (e.success) {
                     var prependMessage='<div class="container_12 grid_6" id="prependMessageID">';
                         prependMessage+='<div class="message-list-info">';

                        prependMessage+='<div class="container_12 grid_1 omega">';
                        prependMessage+='<div class="user-photo level-head level-1">';
                        prependMessage+='</div>';
                        prependMessage+='</div>';
                        prependMessage+='<div class="container_12 grid_5 alpha">';
                        prependMessage+='<div>';
                        prependMessage+='<ul>';
                        prependMessage+='<li><a>'+e.currentDeveloperName+'</a></li>';
                        prependMessage+='</ul>';
                        prependMessage+='</div>';

                        prependMessage+='<div>';
                        prependMessage+=e.content + '&nbsp&nbsp&nbsp';

                        for(var item in e.MessageFiles)
                        {
                        alert(e.MessageFiles[item].FileName);
                        prependMessage+='<img src = "/Content/Files/';
                        prependMessage+=e.currentDeveloperName+'/';
                        prependMessage+=e.MessageFiles[item].FileName;
                        prependMessage+='" alt=""/>';
                        }

                        for(var index in e.messageLinks)
                        {
                            prependMessage+='<a href="'+e.messageLinks[index].LinkHref +'">'+e.messageLinks[index].LinkText +'</a>' ;
                        }
                        prependMessage+='</div>'
                        prependMessage+='<div>'
                        prependMessage+='<a href="javascript:void(0)" class="aLike" data="';
                        prependMessage+=e.currentDeveloperID +'">';
                        prependMessage+='Like';
                        prependMessage+='</a>';
                        prependMessage+='<a href="javascript:void(0)" class="aShare">';
                        prependMessage+='Share';
                        prependMessage+='</a> ';
                        prependMessage+='<a href="javascript:void(0)" class="aReply">';
                        prependMessage+='Reply';
                        prependMessage+='</a>';
                        prependMessage+='</div>';

                        prependMessage+='<div class="replyList">';
                        prependMessage+='</div>';

                        prependMessage+='<div class="treply" data = "'+e.messageID+'" style="padding:2px; border:1px solid #ccc; color:#999;" >';
                        prependMessage+='Write a reply...';
                        prependMessage+='</div>';

                        prependMessage+='</div>';
                        prependMessage+='<div class="clear">';
                        prependMessage+='</div>';
                        prependMessage+='</div>';
                        prependMessage+='<div class="clear">';
                        prependMessage+='</div>';
                        prependMessage+='</div>';

                       $("#test").prepend(prependMessage);
                       clickToBoxHelper.reBind($(prependMessage).find(".treply")[0]);
                       $("#prependMessageID").css("margin-left","0px"); 
                }
            }
        });
    });


</script>
